


import React, { useEffect, useState } from "react"
import { feedbackApi, feebbackListApi } from "../api/api"
import { Input } from "antd-mobile"
import { useHistory } from "react-router-dom"
import Page from "./Page"

export default function PackFeedBack() {

  const [list, setlist] = useState([])
  const [list1, setlist1] = useState([])
  const history = useHistory()

  const [content, setcontent] = useState('')
  const [title, settitle] = useState('')

  // 页数
  const [pageNum, setPageNum] = useState(1)
  // 一页显示数量
  const [pageSize, setPageSize] = useState(5)
  // 总页数
  const [pages, setPages] = useState(1)




  const feebacklist = async (params: any) => {
    const res = await feebbackListApi(params)
    console.log(111111);
    
    setlist1(res.data.rows)
    setPages(Math.ceil(res.data.total / pageSize))
  }

  const add = async (data: any) => {
    const res = await feedbackApi(data)
    console.log(res);
    
    setlist(res.data.rows)
    feebacklist({ pageNum, pageSize })
  }


  async function onChangePage(val: any) {
    feebacklist({
      pageNum: val,
      pageSize: 5
    })
    setPageNum(val)
  }

  const fk = (id: any) => {
    history.push('./ParkFeedBackDetails/' + id)
    // console.log(id);

  }
  useEffect(() => {
    // add()
    feebacklist({ pageNum, pageSize })
  }, [])

  return (
    <div style={{ height: 'calc(100vh - 100px)', overflow: 'auto' }}>
      <div style={{ fontSize: '16px' }}>
        新增意见
      </div>

      <div>
        <div>
          <Input placeholder="请输入新增内容" value={content} onChange={val => { setcontent(val) }} />
        </div>
        <div>
          <Input placeholder="请输入新增标题" value={title} onChange={val => { settitle(val) }} />
        </div>
        <button onClick={() => {
          add({ content, title })
        }}>
          新增
        </button>
        <button onClick={() => {
          feebacklist({ pageNum, pageSize })
        }}>
          查询
        </button>
      </div>
      <div style={{ padding: '5px 0' }} >
        {
          list1.map((item: any, index: any) => {
            return (
              <div onClick={() => {
                fk(item.id)
              }} key={item.id} style={{ border: '1px red solid', padding: '5px 10px' }}>
                <div>{item.title ? item.title : '没有数据'}</div>
                <div>{item.content ? item.content : '没有数据'}</div>
              </div>
            )
          })
        }
      </div>
      <Page onChangePage={onChangePage} pagebtnall={pages} pagebtnnum={5} pagecur={pageNum}></Page>
    </div>
  )
}